# -*- coding:UTF-8 -*-

class findAndDelete:
    #依据sql查询出结果
    def sqlFind(self, logger, sqlconn, sql):
        logger.log(u'查询SQL语句：%s ' % sql)
        result = sqlconn.fetch_all(sql)
        if result and len(result) > 0:
            for res in result:
                logger.log(u'查询结果：%s ' %repr(res).decode('unicode-escape') )
        else:
            logger.log(u'查询结果：NULL ')

    #依据sql执行删除
    def sqlDelete(self, logger, sqlconn, sql):
        logger.log(u'删除SQL语句：%s ' % sql)
        result = sqlconn.update(sql)
        if result:
            logger.log(u'删除结果：True ')
        else:
            logger.log(u'删除结果：False ')

    def monogoFind(self, logger, monconn, param, value):
        result = monconn.find(param,value)
        if result and result.count > 0:
            for res in result:
                logger.log(monconn.dbname + " 库表 " + monconn.tbname + "，参数："
                       + str(param) + ":" + str(value) + '，查询结果：%s ' % repr(res).decode('unicode-escape'))
        else:
            logger.log(monconn.dbname + " 库表 " + monconn.tbname + "，参数："
                       + str(param) + ":" + str(value) + " no data in mongoDB... ")

    def monogoDelete(self, logger, monconn, param, value):
        result = monconn.delete(param, value)
        if result:
            logger.log(u'删除结果：True ')
        else:
            logger.log(u'删除结果：False ')

    def esfind(self, logger, esconn, estype, param, value):
        result = esconn.find(estype, param, value)
        if result and len(result) > 0:
            logger.log("Elasticsearch库 " + estype + " 类型" + "，参数：" + str(param) + "：" +
                       str(value) + '查询结果：%s ' % repr(result).decode('unicode-escape'))
        else:
            logger.log("no data in Elasticsearch... ")

    def esdelete(self, logger, esconn, estype, param, value):
        result = esconn.delete(estype, param, value)
        if result:
            logger.log(u'删除结果：True ')
        else:
            logger.log(u'删除结果：False ')